<template>  
    <div class="news">
        <ul>
            <li v-for="item in newsList" :key="item.id">
            <!-- 第一种写法 -->
                <!-- <RouterLink :to="`/news/detail?id=${item.id}&title=${item.title}&content=${item.content}`">{{item.title}}</RouterLink> -->
                <!-- <RouterLink :to="{
                    path:'/news/detail',
                    query:{
                        id:item.id,
                        title:item.title,
                        content:item.content
                        }
                    }">{{item.title}}</RouterLink> -->
                <!-- <RouterLink :to="`/news/detail/${item.id}/${item.title}/${item.content}`">{{item.title}}</RouterLink> -->
                <button @click="goDetai(item)">查看新闻</button>
                <RouterLink :to="{
                    name:'Detail',
                    params:{
                        id:item.id,
                        title:item.title,
                        content:item.content
                    }
                }"> {{item.title}}</RouterLink>
            
            </li>
        </ul>
        <div class = "pagination">
            <RouterView> </RouterView>
        </div>
    </div>
</template>

<script setup lang="ts" name = "News">
    import { reactive } from 'vue';
    import { useRouter } from 'vue-router';

    const newsList = reactive([
        {id: '001', title:'如何一夜暴富', content:'学IT'},
        {id: '002', title:'震惊！！！！', content:'明天是周一'},
        {id: '003', title:'如何成为超级英雄', content:'做梦'},
    ])

    interface NewsItem {
        id: string;
        title: string;
        content: string;
    }

    const router = useRouter();
    function goDetai(item: NewsItem) {
        // 这些参数和to的语法完全一致
        // router.push({
        //     name:'Detail',
        //         params:{
        //             id:item.id,
        //             title:item.title,
        //             content:item.content
        //         }
        // })
        
        router.replace({
            name:'Detail',
            params:{
                id:item.id,
                title:item.title,
                content:item.content
            }
        })
    }

</script>

<style scoped>
.news  {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
.news  ul {
    margin-top: 30px;
    /* list-style: none; */
    padding-left: 10px;
}
.news li>a {
    color: #60d3b6;
    text-decoration: none;
    font-size: large;
    line-height: 40px;
    border-bottom: 1px solid #60d3b6;
    text-decoration: none;
    text-shadow: 0 0 1px #d3bb31;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
button {
    display: flex;
    justify-content: space-around;
    margin: 0 100px;
}

button a {
    line-height: 40px;
    border-radius: 10px;
    background-color: gray;
    text-decoration: none;
    font-size: 18px;
    letter-spacing: 5px;
}

button a.active {
    display: block;
    text-align: center;
    width: 90px;
    height: 40px;
    line-height: 40px;
    border-radius: 10px;
    background-color: rgb(38, 150, 98);
    text-decoration: none;
    color: rgb(159, 202, 175);
    font-size: 18px;
    letter-spacing: 5px;
}

</style>
